package cn.kgc.controller;

import cn.kgc.entity.LogsInfo;
import cn.kgc.service.LogsInfoService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;

@RestController
@RequestMapping("/logsInfo")
@Api
@Validated
@Slf4j
@CrossOrigin
@SuppressWarnings("all")
public class LogsInfoController {
    @Resource
    private LogsInfoService logsInfoService;

    @GetMapping("/list")
    @ApiOperation(value = "查询所有数据")
    @CrossOrigin
    public List<LogsInfo> selectAll() {
        return logsInfoService.list();
    }

    @GetMapping("/page")
    @ApiOperation(value = "分页查询数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "currentPage", value = "当前页", defaultValue = "1", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "每页显示条数", defaultValue = "5", dataType = "int", paramType = "query")
    })
    @CrossOrigin
    public IPage<LogsInfo> selectPage(@RequestParam(defaultValue = "1") int currentPage,
                                      @RequestParam(defaultValue = "5") int pageSize) {
        IPage<LogsInfo> page = new Page(currentPage, pageSize);

        return logsInfoService.page(page);
    }

    @GetMapping("/detail/{id}")
    @CrossOrigin
    @ApiOperation(value = "查看详细信息")
    @ApiImplicitParam(name = "id", value = "主键", paramType = "path", dataType = "string")
    public LogsInfo selectOne(@PathVariable Serializable id) {
        return this.logsInfoService.getById(id);
    }

    @DeleteMapping("/del/{id}")
    @ApiOperation(value = "根据主键删除")
    @ApiImplicitParam(name = "id", value = "主键", paramType = "path", dataType = "string")
    @CrossOrigin
    public boolean delete(@PathVariable String id) {
        return this.logsInfoService.removeById(id);
    }
}
